home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / stv.lha / STV / ISA / artifact / remfile.st < prev    next >
Text File  |  1993-07-23  |  1KB  |  48 lines

  1.  
  2. "
  3.   File Remove Change by Tom Wrensch & Gene Korienek
  4.  
  5.   I find that I often want to make sure that a file
  6.   has been removed from the disk.  Simply using
  7.   File remove: 'filename.ext' will cause a walkback
  8.   if 'filename.ext' doesn't exist.  My fix is to
  9.   define a new File class message remove:ifAbsent:
  10.   which takes a block as its second argument.  If
  11.   the file is on the disk, fine simply remove it -
  12.   if it isn't on the disk then evaluate the block
  13.   passed in the second argument.
  14.  
  15.   For example lets say I want to remove any old
  16.   versions of the file 'test1.txt' before reuse
  17.   that name.  I could just do this: 
  18.  
  19.     File remove: 'test1.txt' ifAbsent: [].
  20.  
  21.   No blow up !  If I want to do something more
  22.   complicated when the file isn't there I can
  23.   put what I want to happen in the block."!
  24.  
  25. !Dos methods !
  26.  
  27. hasError
  28.     "Answer true if calling dosError: with
  29.      the current register set would cause
  30.      a walkback."
  31. ^((registers at: 17) bitAnd: 1) = 1! ! 
  32.  
  33.  
  34. !File class methods !
  35.  
  36. remove: aString ifAbsent: aBlock
  37.     "Erase the file named aString.  If I can't
  38.      (because it's absent or locked) evaluate
  39.      aBlock."
  40.     | aDos old |
  41.     aDos := Dos new.
  42.     old := aString asAsciiZ.
  43.     aDos setReg: 6 to: old;
  44.          setReg: 3 to: old;
  45.          setRegHigh: 0 to: 16r41;
  46.          interrupt: 16r21.
  47.     aDos hasError ifTrue: aBlock! !
  48.